package com.qersoft.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qersoft.dao.DictionaryTypeDao;
import com.qersoft.entity.DictionaryType;
import com.qersoft.service.DictionaryTypeService;
import org.springframework.stereotype.Service;

@Service
public class DictionaryTypeServiceImpl extends ServiceImpl<DictionaryTypeDao, DictionaryType> implements DictionaryTypeService {

    @Override
    public Integer add(DictionaryType dictionaryType) {
        return baseMapper.insert(dictionaryType);
    }

    @Override
    public boolean delete(Integer id) {
        return removeById(id);
    }

    @Override
    public boolean update(DictionaryType dictionaryType) {
        return updateById(dictionaryType);
    }

    @Override
    public DictionaryType getById(Integer id) {
        // 调用 Mapper 的 selectById 方法
        return baseMapper.selectById(id);
    }


    @Override
    public IPage<DictionaryType> list(DictionaryType dictionaryType, Integer pageNo, Integer pageSize) {
        LambdaQueryWrapper<DictionaryType> wrapper = new LambdaQueryWrapper<>();
        if (dictionaryType.getDicName() != null) {
            wrapper.like(DictionaryType::getDicName, dictionaryType.getDicName());
        }
        if (dictionaryType.getDicType() != null) {
            wrapper.eq(DictionaryType::getDicType, dictionaryType.getDicType());
        }

        IPage<DictionaryType> page = new Page<>(pageNo, pageSize);
        return baseMapper.selectPage(page, wrapper);
    }



}
